package com.ruoyi.community.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.community.domain.vo.ComplainVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.Complain;
import com.ruoyi.community.service.IComplainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投诉意见Controller
 *
 * @author lj
 * @date 2022-02-22
 */
@RestController
@RequestMapping("/community/complain")
public class ComplainController extends BaseController
{
    @Autowired
    private IComplainService complainService;

    /**
     * 查询投诉意见列表
     */
    @PreAuthorize("@ss.hasPermi('community:complain:list')")
    @GetMapping("/list")
    public TableDataInfo list(Complain complain)
    {
        startPage();
        List<ComplainVo> list = complainService.selectComplainLists(complain);
        return getDataTable(list);
    }

    /**
     * 导出投诉意见列表
     */
    @PreAuthorize("@ss.hasPermi('community:complain:export')")
    @Log(title = "投诉意见", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Complain complain)
    {
        List<Complain> list = complainService.selectComplainList(complain);
        ExcelUtil<Complain> util = new ExcelUtil<Complain>(Complain.class);
        util.exportExcel(response, list, "投诉意见数据");
    }

    /**
     * 获取投诉意见详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:complain:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(complainService.selectComplainById(id));
    }

    /**
     * 新增投诉意见
     */
    @PreAuthorize("@ss.hasPermi('community:complain:add')")
    @Log(title = "投诉意见", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Complain complain)
    {
        return toAjax(complainService.insertComplain(complain));
    }

    /**
     * 修改投诉意见
     */
    @PreAuthorize("@ss.hasPermi('community:complain:edit')")
    @Log(title = "投诉意见", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Complain complain)
    {
        return toAjax(complainService.updateComplain(complain));
    }

    /**
     * 删除投诉意见
     */
    @PreAuthorize("@ss.hasPermi('community:complain:remove')")
    @Log(title = "投诉意见", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(complainService.updateComplainByIds(ids));
    }
}
